﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Xml;
using SurveySystem.Model;
using System.Windows.Media;

namespace SurveySystem.Repository
{
    public class XmlSurveyRetrieverRepository : ISurveyRepository
    {
        /// <summary>
        /// Default constructor
        /// </summary>
        public XmlSurveyRetrieverRepository() { }

        public Survey GetSurveyByID(int surveyID)
        {
            //TODO: Check file exists   
            try
            {
                var serializer = new XmlSerializer(typeof(Survey));

                //Must be the property which is set to fire the property changed event
                //TODO: Can we be more flexible with this xml file, e.g. filenames?
                var survey = (Survey)serializer.Deserialize(XmlReader.Create("SurveyModel.xml"));
                return survey;
            }
            catch (Exception ex)
            {
                //TODO: Do something useful#
                // TODO: logging
                throw ex;
            }

            return null;
        }

        public List<Survey> GetAllActiveSurveys()
        {

            List<Survey> list = new List<Survey>();

            list.Add(GetSurveyByID(0));

            return list;

        }

        public List<Survey> GetAllSurveys()
        {
            List<Survey> list = new List<Survey>();

            list.Add(GetSurveyByID(0));

            return list;

        }
        
        public void AddSurvey(Survey s)
        {
            throw new NotImplementedException();
        }

        public void UpdateSurvey(Survey s)
        {
            throw new NotImplementedException();
        }

        public void DeleteSurvey(int surveyID)
        {
            throw new NotImplementedException();
        }

    }
}
